package com.ptu.spzx.controller;


import com.github.pagehelper.PageInfo;
import com.ptu.spzx.domain.Delete.DeleteIds;
import com.ptu.spzx.domain.Exam.Exam;
import com.ptu.spzx.domain.Exam.dto.ExamDTO;
import com.ptu.spzx.domain.Exam.vo.ExamStuVo;
import com.ptu.spzx.domain.Exam.vo.ExamVO;
import com.ptu.spzx.domain.Exam.vo.StuExamScoreVo;
import com.ptu.spzx.model.entity.user.UserInfo;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import com.ptu.spzx.service.IExamService;
import lombok.AllArgsConstructor;
import org.simpleframework.xml.Path;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author YT
 * @since 2024-01-28
 */
@RestController
@RequestMapping("/sc/exam/Exam")
@AllArgsConstructor
public class ExamController {

    private final IExamService iExamService;

    //添加考试
    @PostMapping("/createExam")
    public Result addExam(@RequestBody ExamDTO examDTO) throws ParseException {
        iExamService.addExam(examDTO);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //删除考试
    @DeleteMapping("/deleteExam")
    public Result delExamById(@RequestBody DeleteIds deleteIds) {
        iExamService.delExamById(deleteIds);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //更新考试
    @PostMapping("/updateExam")
    public Result updateExam(@RequestBody ExamDTO examDTO) {
        iExamService.updateExam(examDTO);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //获取考试详细
    @GetMapping("/getExamDetail/{id}")
    public Result getExamDetailById(@PathVariable("id") Long id) {
        ExamVO examDetailById = iExamService.getExamDetailById(id);
        return Result.build(examDetailById, ResultCodeEnum.SUCCESS);
    }

    //根据课程学期获取全部考试
    @GetMapping("/getExamByCourseIdSemester/{courseId}/{pageNum}/{PageSize}")
    public Result getExamByCourseIdSemester(@PathVariable("courseId") Integer courseId,
                                            @RequestParam("semester") String semester,
                                            @PathVariable("pageNum") Integer pageNum,
                                            @PathVariable("PageSize") Integer pageSIze) {
        PageInfo<Exam> examByCourseIdSemester = iExamService.getExamByCourseIdSemester(courseId, semester,pageNum,pageSIze);
        return Result.build(examByCourseIdSemester, ResultCodeEnum.SUCCESS);
    }

    //学生获取详细的考试信息
    @GetMapping("/getStuExam/{stuId}")
    public Result getStuExam(@PathVariable("stuId") String stuId) {
        List stuExam = iExamService.getStuExam(stuId);
        return Result.build(stuExam, ResultCodeEnum.SUCCESS);
    }

   //数据分析，考试提交人数分析
   @GetMapping("/getStuAnalyse/{examId}/{classIds}")
    public Result getStuAnalyse(@PathVariable("examId") Long examId,
                                @PathVariable(required = false,value = "classIds") List<Long> classIds){
        ExamStuVo stuVoInfo=iExamService.getStuAnalyse(examId,classIds);
        return Result.build(stuVoInfo,ResultCodeEnum.SUCCESS);
   }

   //数据分析，学生成绩分析
   @GetMapping("/getStuScoreAnalyse/{examId}/{classId}")
   public Result getStuScoreAnalyse(@PathVariable("examId") Long examId,
                                    @PathVariable(value = "classId") Long classId){
        StuExamScoreVo stuExamScoreVo=iExamService.getStuScoreAnalyse(examId,classId);
        return Result.build(null,ResultCodeEnum.SUCCESS);
   }

    //根据考试Id获取全部的考试学生
   @GetMapping("/getExamStuNum/{examId}/{pageNum}/{pageSize}")
   public Result  getExamStuNum(@PathVariable("examId") Long examId,
                                @PathVariable("pageNum") Integer pageNum,
                                @PathVariable("pageSize") Integer pageSize){
   PageInfo<UserInfo> pageInfo=iExamService.getExamStuNum(examId,pageNum,pageSize);
   return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
}
}

